package com.party.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.DataSource;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.core.page.TableDataInfo;
import com.party.common.enums.BusinessType;
import com.party.common.enums.DataSourceType;
import com.party.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.business.domain.TopicLibrary;
import com.party.business.service.ITopicLibraryService;

/**
 * 专题Controller
 *
 * @author ruoyi
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/business/library" )
public class TopicLibraryController extends BaseController {
    @Autowired
    private ITopicLibraryService topicLibraryService;

/**
 * 查询专题列表
 */
//@RequiresPermissions("business:library:list")
@GetMapping("/list" )
@DataSource(value = DataSourceType.SLAVE)
    public TableDataInfo list(TopicLibrary topicLibrary) {
        startPage();
        List<TopicLibrary> list = topicLibraryService.selectTopicLibraryList(topicLibrary);
        return getDataTable(list);
    }

    /**
     * 导出专题列表
     */
    //@RequiresPermissions("business:library:export")
    @Log(title = "专题" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TopicLibrary topicLibrary) {
        List<TopicLibrary> list = topicLibraryService.selectTopicLibraryList(topicLibrary);
        ExcelUtil<TopicLibrary> util = new ExcelUtil<TopicLibrary>(TopicLibrary. class);
        util.exportExcel(response, list, "专题数据" );
    }

    /**
     * 获取专题详细信息
     */
    //@RequiresPermissions("business:library:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(topicLibraryService.getById(id));
    }

    /**
     * 新增专题
     */
    //@RequiresPermissions("business:library:add")
    @Log(title = "专题" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TopicLibrary topicLibrary) {
        return toAjax(topicLibraryService.save(topicLibrary));
    }

    /**
     * 修改专题
     */
    //@RequiresPermissions("business:library:edit")
    @Log(title = "专题" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TopicLibrary topicLibrary) {
        return toAjax(topicLibraryService.updateById(topicLibrary));
    }

    /**
     * 删除专题
     */
    //@RequiresPermissions("business:library:remove")
    @Log(title = "专题" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(topicLibraryService.removeByIds(Arrays.asList(ids)));
    }
}
